<style lang="less">
  .filter-category {
    margin: 0 auto;
    background: #fff;
    padding: 1em 0;
    font-size: 14px;
    .item {
      width: 1190px;
      margin: 1em auto;
      display: flex;
      align-items: baseline;
      align-content: flex-start;
      line-height: 150%;
      h2 {
        background: #ddd;
        font-size: 100%;
        text-align: center;
        min-width: 4em;
        font-weight: normal;
        padding: 4px 6px;
      }
      ul {
        flex: 1 1 0;
        min-width: 0;
        margin-left: 1em;
        display: flex;
        flex-wrap: wrap;
        li {
          margin-right: .5em;
          a {
            color: #222;
            display: inline-block;
            padding: .3em .6em;
            border-radius: 5px;
          }
          &.active a {
            background: #0061ae;
            color: #fff;
          }
        }
      }
    }
  }
</style>

<template>
  <div class="filter-category">
    <div class="item" v-for="item in list">
      <h2 v-text="item.name"></h2>
      <ul>
        <li :class="{active: index === item.currentIndex || (item.currentIndex===undefined && index ===0)}"
            v-for="(field, index) in item.data">
          <a href="javascript:void(0)" @click="click(index, item)">{{field.label}}</a>
        </li>
      </ul>
    </div>
  </div>
</template>


<script>
  export default {
    props: {
      list: {
        type: Array
      }
    },
    methods: {
      click (index, item) {
        this.$set(item, 'currentIndex', index)
        let param = {}
        this.list.filter((item) => {
          let index = item.currentIndex
          param[item.field] = item.data[index === undefined ? 0 : index].value
        })
        this.$emit('change', param)
      }
    }
  }
</script>
